package com.itheima.job4;

import java.io.*;
import java.net.Socket;
import java.util.List;

public class ServerThread implements Runnable{
    private Socket socket;

    public ServerThread(Socket socket) {
        this.socket = socket;
    }

    public ServerThread() {

    }

    @Override
    public void run() {
        try {
            InputStream is = new FileInputStream("E:/test/file/image.png");
            //向每个socket对象发送数据
            byte[] buf = new byte[1024];
            OutputStream outputStream = socket.getOutputStream();
            int len ;
            while ((len = is.read(buf))!=-1){
                outputStream.write(buf,0,len);
            }
            //传输完文件要告知客户端结束
            socket.shutdownOutput();
            is.close();
            socket.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


}
